﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>普通字段属性</title>
    <script language="JavaScript" src="../../Comm/JScript.js" type="text/javascript" ></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript" >

        //DataType定义
        var AppString = 1;
        var AppInt = 2;
        var AppFloat = 3;
        var AppBoolean = 4;
        var AppDouble = 5;
        var AppDate = 6;
        var AppDateTime = 7;
        var AppMoney = 8;

        /* ESC Key Down */
        function Esc() {
            if (event.keyCode == 27)
                window.close();
            return true;
        }
        function Copy() {
            var val = $("#TB_KeyOfEn").val();

            //对于火狐不兼容. #warning.
            clipboardData.setData('Text', val);
            alert('已经把字段[' + val + ']copy到粘帖版上');
        }

        function SetButtonSta(sta) {
            $("Btn_Save").attr("disabled", sta);
            $("Btn_SaveAndClose").attr("disabled", sta);
            $("Btn_SaveAndNew").attr("disabled", sta);
            $("Btn_New").attr("disabled", sta);
        }

        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            //绑定字段分组.
            InitPage();

            //初始化groupID.
            var fk_mapData = GetQueryString("FK_MapData");
             
            $("#Msg").html("");

        });

        function InitPage() {

            var mypk = GetQueryString("MyPK");
            var keyOfEn = GetQueryString("KeyOfEn");
            var fk_mapData = GetQueryString("FK_MapData");

            var fType = GetQueryString("FType");
            if (fType == null || fType == "none")
                fType = AppString;
            else
                fType = parseInt(fType);

            if (fType != AppString) {
                //非string类型，就默认把他屏蔽掉. 
                //必填项都放出来 杨玉慧
                // document.getElementById("tr0").style.display = 'none';
                document.getElementById("tr1").style.display = 'none';
                document.getElementById("tr2").style.display = 'none';
                document.getElementById("tr3").style.display = 'none';
                //document.getElementById("tr4").style.display = 'none';
                $('#tr4 td:nth(1)').css('display', 'none');
                $('#tr4 td:nth(2)').css('display', 'none');
                //  document.getElementById("tr5").style.display = 'none';
                //  document.getElementById("tr6").style.display = 'none';
            }

            switch(fType) {
                case AppString:
                case AppBoolean:
                case AppDate:
                case AppDateTime:
                    document.getElementById("tr14").style.display = 'none';
                    break;
            }

            //设置不可以用.
            SetButtonSta('true');

            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=EditF_FieldInit&MyPK=" + mypk + "&FType=" + fType + "&FK_MapData=" + fk_mapData + "&KeyOfEn=" + keyOfEn + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {

                    // alert(data);
                    data = JSON.parse(data);
					//杨玉慧 改JSON类
					if (data instanceof Array) {//判断是否是数组 如果是数组就取第一个对象 杨玉慧
                        data = data[0];
                    }
                    var mypk = data.FK_MapData + '_' + data.KeyOfEn;
                    keyOfEn = data.KeyOfEn;

                    //给公共属性赋值.
                    $("#TB_Name").val(data.Name);
                    $("#TB_KeyOfEn").val(data.KeyOfEn);
                    $("#TB_DefVal").val(data.DefVal);

                    $("#DDL_ColSpan").val(data.ColSpan);   //跨的列数.
                    $("#TB_FontSize").val(data.FontSize);  //字体大小.

                    //alert(data.Tip);

                    $("#TB_Tip").val(data.Tip);  //字体大小.

                    //所在的字段分组.
                    var groupID = 0;
                    if (data.GroupID != 0)
                        groupID = data.GroupID;

                    GenerBindSQL("DDL_GroupID", "GroupField", "@FK_MapData=" + GetQueryString("FK_MapData"), "NO", "NAME", groupID);
                    
                    //是否可以编辑？
                    $("#RB_UIIsEnable_" + data.UIIsEnable).attr('checked', 'checked');
                    $("#RB_UIVisible_" + data.UIVisible).attr('checked', 'checked');

                    //是否必填项.
                    if (data.UIIsInput == true)
                        $("#CB_IsInput").attr("checked", true);

                    //是否是大块文本.
                    if (data.IsSupperText == true)
                        $("#CB_IsSupperText").attr("checked", true);

                    //是否是富文本?
                    if (data.IsRichText == true)
                        $("#CB_IsRichText").attr("checked", true);

                    //是否合计?
                    if (typeof data.IsSum == "undefined" || data.IsSum == true)
                        $("#CB_IsSum").attr("checked", true);

                    var htmlLink = "";
                    if (data.MyDataType == AppString) {

                        //最大最小长度.
                        $("#TB_MinLen").val(data.MinLen);
                        $("#TB_MaxLen").val(data.MaxLen);
                        $("#TB_UIWidth").val(data.UIWidth);  //宽度..

                        //默认值.
                        $("#DDL_DefVal").val(data.DefVal); // 设置默认值.

                        // 如果是日期格式， 当下拉框选择值的时候，让其进行给tb赋值。
                        $("#DDL_DefVal").change(function () {
                            var checkValue = $("#DDL_DefVal").val();
                            $("#TB_DefVal").val(checkValue);
                        });

                        // 清空默认值, 写一个循环把数据给值.
                        $("#DDL_Rows").empty();
                        for (var i = 1; i < 30; i++) {
                            $("#DDL_Rows").append("<option value='" + i + "'>" + i + "行</option>");
                        }
                        //计算文本框的行数.
                        var rows = data.UIHeight / 23;
                        if (rows <= 0)
                            rows = 1;

                        rows = parseInt(rows);
                        $("#DDL_Rows").val(rows); //行数.
                        
                        htmlLink += "<a href=\"javascript:WinOpen('./MapExt/PopVal.htm?FK_MapData=" + fk_mapData + "&KeyOfEn=" + keyOfEn + "&MyPK=PopVal_" + mypk + "')\">设置开窗返回值</a>";
                        htmlLink += "-<a href=\"javascript:WinOpen('./MapExt/RegularExpression.htm?FK_MapData=" + fk_mapData + "&KeyOfEn=" + keyOfEn + "&OperAttrKey=" + mypk + "')\">正则表达式</a>";
                        htmlLink += "-<a href=\"javascript:WinOpen('./MapExt/TBFullCtrl.htm?FK_MapData=" + fk_mapData + "&KeyOfEn=" + keyOfEn + "&MyPK=TBFullCtrl_" + mypk + "')\">文本框自动完成</a>";
                        htmlLink += "-<a href=\"javascript:WinOpen('./MapExt/InputCheck.htm?FK_MapData=" + fk_mapData + "&RefNo=" + mypk + "&KeyOfEn=" + keyOfEn + "')\">脚本验证</a>";

                        //自动计算.
                        // htmlLink += "-<a href=\"javascript:WinOpen('./MapExt/AutoFull.htm?FK_MapData=" + fk_mapData + "&ExtType=AutoFull&RefNo=" + mypk + "')\">自动计算</a>";

                        htmlLink += "-<a href=\"javascript:WinOpen('EditFExtContral.htm?FK_MapData=" + fk_mapData + "&KeyOfEn=" + keyOfEn + "')\">扩展控件</a>";
                    }

                    //如果是日期类型的.
                    if (data.MyDataType == AppDate || data.MyDataType == AppDateTime) {

                        //清空默认值.
                        $("#DDL_DefVal").empty();
                        $("#DDL_DefVal").append("<option value=''>默认值</option>");
                        $("#DDL_DefVal").append("<option value='@RDT'>当前日期</option>");

                        //设置事件.
                        $("#DDL_DefVal").change(function () {
                            var checkValue = $("#DDL_DefVal").val();
                            $("#TB_DefVal").val(checkValue);

                        });

                        //设置默认值.
                        $("#DDL_DefVal").val(data.DefVal);

                        htmlLink += "-<a href=\"javascript:WinOpen('./MapExt/RegularExpression.htm?FK_MapData=" + fk_mapData + "&RefNo=" + keyOfEn + "&OperAttrKey=" + mypk + "')\">正则表达式</a>";
                        htmlLink += "-<a href=\"javascript:WinOpen('./MapExt/InputCheck.htm?FK_MapData=" + fk_mapData + "&RefNo=" + mypk + "')\">脚本验证</a>";
                        htmlLink += "-<a href=\"javascript:WinOpen('./MapExt/AutoFull.htm?FK_MapData=" + fk_mapData + "&ExtType=AutoFull&RefNo=" + mypk + "')\">自动计算</a>";
                    }

                    //boolen 类型.
                    if (data.MyDataType == AppBoolean) {

                        //清空默认值.
                        $("#DDL_DefVal").empty();
                        $("#DDL_DefVal").append("<option value='0'>默认否</option>");
                        $("#DDL_DefVal").append("<option value='1'>默认是</option>");

                        //设置事件.
                        $("#DDL_DefVal").change(function () {
                            var checkValue = $("#DDL_DefVal").val();
                            $("#TB_DefVal").val(checkValue);
                        });

                        //设置默认值.
                        $("#DDL_DefVal").val(data.DefVal);
                    }

                    //对于num类型的数据，隐藏控件,不让其在选择默认值了.
                    if (data.MyDataType == AppInt || data.MyDataType == AppFloat || data.MyDataType == AppMoney) {

                        document.getElementById("DDL_DefVal").style.visibility = "hidden";

                        $("#TB_UIWidth").val(data.UIWidth);  //宽度..


                        htmlLink += "<a href=\"javascript:WinOpen('./MapExt/AutoFull.htm?FK_MapData=" + fk_mapData + "&ExtType=AutoFull&RefNo=" + mypk + "')\">自动计算</a>";
                    }

                    if (htmlLink == "")
                        htmlLink = "无";

                    //设置超链接属性.
                    $("#htmlLink").html(htmlLink);
                }
            });
        }
    </script>
    <base target="_self" /> 
    <link href="../../Comm/Style/Table0.css" rel="stylesheet" type="text/css" />
</head>
<body onkeypress="Esc()" >

<form name='cc' id='cc'>

<center>
<table>
<tr> 
<td>字段中文名称 </td>
<td><input type="text" id="TB_Name" name="TB_Name" /> </td>
<td>显示的标签 </td>
</tr>

<tr> 
<td>字段英文名 </td>
<td><input type="text" id="TB_KeyOfEn" name="TB_KeyOfEn" /> </td>
<td> <a href="javascript:Copy()" ><img src='../../Img/Btn/Copy.gif' class='ICON' alt='复制字段到粘帖板' />复制</a>,用于创建字段.
</td>
</tr>

 
<tr> 
<td>默认值</td>
<td> <input type="text" id="TB_DefVal" name="TB_DefVal" /></td>

<td>

<select name="DDL_DefVal" id="DDL_DefVal"> 
<option value="">选择系统约定默认值</option>
	<option value="@WebUser.No">登陆人员账号</option>
	<option value="@WebUser.Name">登陆人员名称</option>
	<option value="@WebUser.FK_Dept">登陆人员部门编号</option>
	<option selected="selected" value="@WebUser.FK_DeptName">登陆人员部门名称</option>
	<option value="@WebUser.FK_DeptFullName">登陆人员部门全称</option>
	<option value="@yyyy年MM月dd日">当前日期-1</option>
	<option value="@yy年MM月dd日">当前日期-2</option>
	<option value="@FK_ND">当前年度</option>
	<option value="@FK_YF">当前月份</option>
	<option value="@CurrWorker">当前工作可处理人员</option>
</select> 

 </td>
</tr>


<tr> 
<td colspan=2><input  type="radio" id="RB_UIIsEnable_1" name="RB_UIIsEnable" value="1" /> <label for="RB_UIIsEnable_1">可编辑</label> <input  type="radio" id="RB_UIIsEnable_0" name="RB_UIIsEnable" value="0" /> <label for="RB_UIIsEnable_0">不可编辑</label></td>
<td>
<input  type="radio" id="RB_UIVisible_1" name="RB_UIVisible" value="1" /> <label for="RB_UIVisible_1">否界可见</label> <input  type="radio" id="RB_UIVisible_0" name="RB_UIVisible" value="0" /> <label for="RB_UIVisible_0">否界不可见</label>
 </td>
</tr>
 

<tr id='tr1' > 
<td>最小长度 </td>
<td><input type="text" id="TB_MinLen" name="TB_MinLen"  value="0" /> </td>
<td>建议为0. </td>
</tr>

<tr id='tr2' > 
<td>最大长度 </td>
<td> <input type="text" id="TB_MaxLen" name="TB_MaxLen" /> </td>
<td>sqlserver不要超过4000</td>
</tr>
   
 <tr id='tr6' > 
<td>文本框宽度 </td>
<td> <input type="text" id="TB_UIWidth" name="TB_UIWidth" /> </td>
<td>对从表有效.</td>
</tr>

<tr id='tr3' > 
<td>文本框行数 </td>
<td> <select name="DDL_Rows" id="DDL_Rows"> 
	<option value="4">4</option>
</select>  </td>
<td>一行是23px高度.</td>
</tr>

<tr id='tr4'> 
<td><input  type="checkbox"  value="是否是必填字段？" name="CB_IsInput" id="CB_IsInput" /> <label for="CB_IsInput">是否是必填字段？</label>  </td>
<td><input  type="checkbox"  value="是否大块文本？" name="CB_IsSupperText" id="CB_IsSupperText" /> <label for="CB_IsSupperText">是否大块文本？</label>  </td>
<td><input  type="checkbox"  value="是否富文本？" name="CB_IsRichText" id="CB_IsRichText"  /> <label for="CB_IsRichText">是否富文本？</label>  </td>
</tr>


<tr id='tr5'> 
<td >横跨的列数 </td>
<td >
<select name="DDL_ColSpan" id="DDL_ColSpan"> 
    <option value="1">1</option>
	<option value="3">3</option>
	<option value="4">4</option>
</select> 

 </td>
<td >对傻瓜表单有效 </td>
</tr>

<tr id='tr7' > 
<td>操作提示 </td>
<td>  
<input type="text" id="Text1" name="TB_Tip" />
</td>
<td>当文本框被激活的时候，提示的信息.</td>
</tr>

<!-- end string 属性. -->


<tr> 
<td>字段分组 </td>
<td>
<select name="DDL_GroupID" id="DDL_GroupID"> 
</select> 

 </td>
<td> 对于傻瓜表单有效.</td>
</tr>

<tr> 
<td>字体大小 </td>
<td>
<select name="TB_FontSize" id="TB_FontSize"> 
<option value="0">默认</option>
	<option value="10">10px</option>
	<option value="11">11px</option>
	<option value="12">12px</option>
	<option value="13">13px</option>
	<option value="14">14px</option>
	<option value="15">15px</option>
	<option value="16">16px</option>
	<option value="17">17px</option>
	<option value="18">18px</option>
	<option value="19">19px</option>
	<option value="20">20px</option>
	<option value="21">21px</option>
	<option value="22">22px</option>
	<option value="23">23px</option>
	<option value="24">24px</option>
	<option value="25">25px</option>
	<option value="26">26px</option>
	<option value="27">27px</option>
</select> 

</td>
<td> </td>
</tr>

<!-- 数值类是否合计.added by liuxc,2017-1-9 -->
<tr id="tr14">
<td>是否合计</td>
<td><input  type="checkbox"  name="CB_IsSum" id="CB_IsSum" /> <label for="CB_IsSum">合计</label></td>
</tr>
<!-- 相关功能的设置. -->
<tr>
<td>高级设置</td>
<td colspan=2> <div id='htmlLink' /></td>
</tr>

<!-- 按钮控制. -->
<tr> 
<td colspan="3">
<input type="button"  value='保存' onclick='Save(this)' id="Btn_Save" name="Btn_Save" />
<input type="button"  value='保存&并关闭' onclick='Save(this)' id="Btn_SaveAndClose" name="Btn_SaveAndClose" />
<input type="button"  value='保存&新建' onclick='Save(this)' id="Btn_SaveAndNew" name="Btn_SaveAndNew" />
<input type="button"  value='删除' onclick='Del()' id="Btn_Del" name="Btn_Del" />
<input type="button"  value='新建' onclick='New()' id="Btn_New" name="Btn_New" />
</td>
</tr>
</table>
<div id="Msg" ></div>
</center>

</form>

<script type="text/javascript">

    //新建.
    function New() {
        var fk_mapData = GetQueryString("FK_MapData");
        var groupID = GetQueryString("GroupField");
        var fType = GetQueryString("FType");

        //#warning 这里一直弹出窗口,怎么解?
        window.location.href = 'FieldTypeList.htm?GroupField=' + groupID + '&FK_MapData=' + fk_mapData + '&FType=' + fType;
        return;
    }
    //删除.
    function Del() {

        var name = $("#TB_Name").val();
        var keyOfEn = $("#TB_KeyOfEn").val();
        if (confirm('您确定要删除['+name+','+keyOfEn+']吗？') == false)
            return;

        $.ajax({
            type: 'post',
            async: true,
            url: Handler + "?DoType=FieldDelete&MyPK=" + GetQueryString("MyPK") + "&m=" + Math.random(),
            dataType: 'html',
            success: function (data) {

                if (data.indexOf("err@") >=0 ) {
                    alert(data);
                    return;
                }

                window.close();
                return;
            }
        });
    }
    //保存.
    function Save( btnCtl ) {


        $("#Msg").html("正在保存,请稍后......");

        var mypk = GetQueryString("MyPK");
        var keyOfEn = GetQueryString("KeyOfEn");
        var fk_mapData = GetQueryString("FK_MapData");
        var groupID = GetQueryString("GroupField");
        var fType = GetQueryString("FType");
        var inlayer = GetQueryString("inlayer");

        if (fType == null || fType == "")
            fType = AppString;

        var frmData = $("#cc").serialize();
        frmData = DoCheckboxValue(frmData, "CB_IsInput");
        frmData = DoCheckboxValue(frmData, "CB_IsSupperText");
        frmData = DoCheckboxValue(frmData, "CB_IsRichText");
        frmData = DoCheckboxValue(frmData, "CB_IsSum");

        $.ajax({
            data: frmData,
            type: 'post',
            async: true,
            url: Handler + "?DoType=EditF_Save&MyPK=" + mypk + "&FType=" + fType + "&LGType=0&FK_MapData=" + fk_mapData + "&KeyOfEn=" + keyOfEn + "&GroupField=" + groupID + "&m=" + Math.random(),
            dataType: 'html',
            success: function (data) {

                if (btnCtl.id == 'Btn_Save') {
                    $("#Msg").html("<font color=green>" + data + "</font>");
                    return;
                }

                if (btnCtl.id == 'Btn_SaveAndClose') {
                    $("#Msg").html("<font color=green>" + data + "</font>");

                    if (inlayer == "1") {
                        var pwin = window.parent;
                        while (pwin) {
                            if (pwin.closeDlg) {
                                pwin.closeDlg();
                                break;
                            }
                            else {
                                pwin = pwin.parent;
                            }
                        }
                    }
                    else {
                        window.close();
                    }

                    return;
                }

                if (btnCtl.id == 'Btn_SaveAndNew') {
                    // alert(data);
                    $("#Msg").html("<font color=green>" + data + "</font>");

                    //#warning 这里一直弹出窗口,怎么解?
                    window.location.href = 'FieldTypeList.htm?GroupID=' + groupID + '&FK_MapData=' + fk_mapData + '&FType=' + fType;
                    return;
                }
            }
        });
    }
</script>

</body>
</html>
